import { getProvinceApi } from "@/api/common";
import { reactive, ref } from "vue";

export default function InitHook() {
  const formState = reactive<Partial<ClientAddressManagement.AddPickupAddressForm>>({
    stateCode: undefined,
    state: undefined,
    cityCode: undefined,
    city: undefined,
    zoneCode: undefined,
    zone: undefined,
    streetCode: undefined,
    street: undefined,
    address: undefined,
    contact1: undefined,
    phone1: undefined,
    contact2: undefined,
    phone2: undefined,
    cityModel: []
  });
  const loading = ref<boolean>(false);
  const formDataRef = ref<any>(null);
  const areaOpts = ref<Array<Base.GeneraDataType>>([]);
  const streetOpts = ref<Array<Base.GeneraDataType>>([]);
  const getAreaOpts = () => {
    return getProvinceApi().then((res: any) => {
      const { code, data } = res;
      if (code === 200) {
        areaOpts.value = data;
      }
    });
  };
  return {
    formState,
    formDataRef,
    loading,
    getAreaOpts,
    areaOpts,
    streetOpts
  };
}
